package com.tubeonfire.controller.admin;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tubeonfire.entity.SpecialTube;
import com.tubeonfire.entity.Tube;
import com.tubeonfire.model.admin.SpecialTubeModel;
import com.tubeonfire.model.admin.TubeModel;

@SuppressWarnings("serial")
public class ListSlideShowServlet extends HttpServlet {

	private static final Logger log = Logger.getLogger(ListSlideShowServlet.class
			.getName());

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {
		try {
			List<Tube> listResult = new ArrayList<Tube>();
			SpecialTube spTube = SpecialTubeModel.getByType("slide", false);
			if (spTube != null) {
				for (String strId : spTube.getListTubeId()) {
					Tube tub = TubeModel.getById(strId, true);
					if (tub != null) {
						listResult.add(tub);
					}
				}
			}
			req.setAttribute("result", listResult);
			req.getRequestDispatcher("/admin/list_slideshow.jsp").forward(req,
					resp);
		} catch (Exception e) {
			log.warning(e.toString());
			e.printStackTrace();
			resp.sendError(4004,
					"We are sorry for the inconvenience ! Please try again later !");
		}
	}
}
